package com.huiquan.framework.utils;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.ReflectionUtils;  
   
/** 
 * 反射调用通用方法
 * className service注解方式，自动生成以首字母小写的类名为bean name
 *   fzl
 *  MOSTsView 3.0 2017-6-2
 */  
public class SpringInvokeUtils {
	@SuppressWarnings("rawtypes")
	public static Object invoke(String className , String method,Object[] objs) throws ClassNotFoundException{
		List<Class> list = new ArrayList<>();
		for(int i = 0 ; i <objs.length;i++){
			Class c  = objs[i].getClass();
			list.add(c);
		}
		Method  mh  = ReflectionUtils.findMethod(SpringContextUtil.getBean(className).getClass(), method,list.toArray(new Class[0]) ); 
		Object obj = ReflectionUtils.invokeMethod(mh,  SpringContextUtil.getBean(className),objs);  
		return obj;
	}
	@SuppressWarnings("rawtypes")
	public static Object invoke(String className , String method,Class[] cls,Object[] objs) throws ClassNotFoundException{
		Method  mh  = ReflectionUtils.findMethod(SpringContextUtil.getBean(className).getClass(), method,cls ); 
		Object obj = ReflectionUtils.invokeMethod(mh,  SpringContextUtil.getBean(className),objs);  
		return obj;
	}
}  